using System;
using UnityEngine;

[Serializable]
public class Developers_0020Friend1 : MonoBehaviour
{
	public GUISkin skin;

	public AudioClip clip;

	public GameObject checkPurchases;

	public Vector2 scrollPosition;

	public int numRows;

	public Vector2 rowSize;

	public Vector2 windowMargin;

	public Vector2 listMargin;

	private Rect windowRect;

	private float originalWidth;

	private float originalHeight;

	public Vector2 scale;

	public int tune;

	public float fStopThreshold;

	public float coef;

	public float smoothcoef;

	private float fResistanceFactor;

	private bool bTranslating;

	private Vector3 v3StartPos;

	private Vector3 v3LastPos;

	private Vector3 v3Delta;

	private float fStartTime;

	private float scrollPositionL;

	private float scrh;

	public Developers_0020Friend1()
	{
		originalWidth = 640f;
		originalHeight = 360f;
		tune = 20000;
		fStopThreshold = 1f;
		coef = 850f;
		smoothcoef = 0.05f;
		fResistanceFactor = 0.9f;
	}

	public void Start()
	{
		scrh = Screen.height;
		if (PlayerPrefs.GetInt("tmp") == 7)
		{
			gameObject.SetActiveRecursively(state: true);
		}
	}

	public void Update()
	{
		if (Input.GetMouseButtonDown(0))
		{
			bTranslating = false;
			v3StartPos = UnityEngine.Input.GetTouch(0).position;
			v3LastPos = v3StartPos;
			fStartTime = Time.time;
		}
		if (Input.GetMouseButtonUp(0))
		{
			v3Delta = UnityEngine.Input.GetTouch(0).position;
			if (v3Delta == v3LastPos)
			{
				v3StartPos = v3Delta;
				fStartTime = Time.time;
			}
			v3Delta = (v3Delta - v3StartPos) / (Time.time - fStartTime);
			bTranslating = true;
			if (!(Mathf.Abs(v3Delta.y) >= 300f))
			{
				v3Delta.y = 0f;
			}
		}
		if (Input.GetMouseButton(0))
		{
			Vector3 a = UnityEngine.Input.GetTouch(0).position;
			if (v3Delta == v3LastPos)
			{
				v3StartPos = UnityEngine.Input.GetTouch(0).position;
				v3LastPos = v3StartPos;
				fStartTime = Time.time;
			}
			Vector2 vector = a - v3LastPos;
			vector.x = 0f;
			vector.y /= scrh;
			scrollPosition.y += vector.y * coef;
			scrollPositionL = scrollPosition.y;
			v3LastPos = a;
		}
		if (bTranslating && !(v3Delta.magnitude <= 10f))
		{
			scrollPositionL += v3Delta.y * smoothcoef;
			v3Delta *= fResistanceFactor;
			if (!(v3Delta.magnitude >= fStopThreshold))
			{
				bTranslating = false;
			}
		}
		if (!Input.GetMouseButton(0))
		{
			scrollPosition.y = Mathf.Lerp(scrollPosition.y, scrollPositionL, Time.deltaTime * 8f);
		}
	}

	public void CheckRes()
	{
		if (Screen.height > 700)
		{
			numRows = tune / (Screen.height + 50);
		}
		else
		{
			numRows = tune / (Screen.height + 380);
		}
		if (Screen.width > 640)
		{
			scale.x = ((float)Screen.width + 0f) / originalWidth;
			scale.y = ((float)Screen.height + 0f) / originalHeight;
		}
		else
		{
			scale.x = 1f;
			scale.y = 1f;
		}
		if (Screen.width > 1020)
		{
			scale.x = 1024f / originalWidth;
			scale.y = 600f / originalHeight;
		}
	}

	public void OnGUI()
	{
		GUI.skin = skin;
		windowRect = new Rect(windowMargin.x, windowMargin.y, (float)Screen.width - 2f * windowMargin.x, (float)Screen.height - 2f * windowMargin.y);
		GUI.Window(0, windowRect, DoWindow, "Spin-Tops Supporter");
	}

	public void DoWindow(int windowID)
	{
		Vector2 vector = new Vector2(windowRect.width - 2f * listMargin.x, windowRect.height - 2f * listMargin.y);
		Rect position = new Rect(listMargin.x, listMargin.y, vector.x, vector.y);
		Rect viewRect = new Rect(0f, 0f, rowSize.x, (float)numRows * rowSize.y);
		scrollPosition = GUI.BeginScrollView(position, scrollPosition, viewRect, alwaysShowHorizontal: false, alwaysShowVertical: false);
		GUILayout.Label("Thank you really much for buying the Spin-Tops In-App Purchase and supporting me and the development of this game and my future games!");
		GUILayout.Label("This list will show what you got currently with the purchase. It will be updated when more content have been done that is only enabled to In-App Purchasers.");
		GUILayout.Label(string.Empty);
		GUILayout.Label("* Removed pop-up ads and banner ads");
		GUILayout.Label("* Unlocked exclusive colorful new stadium: 'Marching Cubes'");
		GUILayout.Label("* Supporter badge in Main Menu");
		GUILayout.Label("* More content is coming with updates...");
		GUILayout.Label(string.Empty);
		GUI.contentColor = new Color(0f, 0.69f, 1f);
		GUILayout.Label("Thank You for downloading and playing Spin-Tops!");
		GUILayout.Label("Mikko E. (Miksumortti)");
		GUI.contentColor = Color.white;
		if (GUILayout.Button("Close", GUILayout.Width(240f * scale.x), GUILayout.Height(32f * scale.y)))
		{
			AudioSource.PlayClipAtPoint(clip, Camera.main.transform.position);
			scrollPosition.y = 0f;
			gameObject.SetActive(false);
			StateManager.state = State.Neutral;
		}
		if (GUILayout.Button("Send E-mail To Developer", GUILayout.Width(240f * scale.x), GUILayout.Height(32f * scale.y)))
		{
			AudioSource.PlayClipAtPoint(clip, Camera.main.transform.position);
			Application.OpenURL("mailto:contact.miksumortti@gmail.com?subject=Spin-Tops User Mail&body=Write your bug, question or whatever here. Please write in English or Finnish. Thanks!");
		}
		if (GUILayout.Button("miksumortti.com", GUILayout.Width(240f * scale.x), GUILayout.Height(32f * scale.y)))
		{
			AudioSource.PlayClipAtPoint(clip, Camera.main.transform.position);
			Application.OpenURL("http://miksumortti.com");
		}
		if (GUILayout.Button("Rate (Google Play Store)", GUILayout.Width(240f * scale.x), GUILayout.Height(32f * scale.y)))
		{
			AudioSource.PlayClipAtPoint(clip, Camera.main.transform.position);
			PlayerPrefs.SetInt("Rated", 1);
			Application.OpenURL("market://details?id=fi.Miksumortti.SpinTops");
		}
		GUI.EndScrollView();
	}

	public void Main()
	{
		InvokeRepeating("CheckRes", 0f, 0.2f);
	}
}
